home *** CD-ROM | disk | FTP | other *** search
/ Unreal Tournament Game Programming for Teens / UnrealTournamentGameProgrammingForTeens.iso / Chapter Files / Chapter06 / Math.txt < prev    next >
Encoding:
Text File  |  2006-10-16  |  1.1 KB  |  46 lines

  1. //========================================================
  2. // Math.
  3. //see Math.txt
  4. //========================================================
  5. class Math extends Actor;
  6.  
  7.  
  8. // #1 Takes two arguments of the type float
  9. //  and returns a value of the type float
  10. public function float Add(float NumA, float Numb){
  11.    return NumA + NumB;
  12. }
  13.  
  14. public function float Subtract(float NumA, float Numb){
  15.    return NumA - NumB;
  16. }
  17.  
  18. public function float Multiply(float NumA, float Numb){
  19.    return NumA * NumB;
  20. }
  21.  
  22. public function float DivideAbyB(float NumA, float Numb){
  23.  
  24.    // #2 Declare a variable that is not 
  25.    // visible to other functions
  26.    local float Result;
  27.    Result = 0; 
  28.    if(NumB != 0){
  29.      Result = NumA/NumB;   
  30.    }
  31.    return Result;
  32. }
  33.  
  34. public function float AverageTwoNumbers(float First, float Second){
  35.  
  36.     local float AddedNumbers;
  37.  
  38.     //#3 Call add from within the class
  39.     //Assign the returned value of Add()
  40.     AddedNumbers = Add(First, Second);
  41.     
  42.     //#4 When you assign a new value, you clear the old
  43.     AddedNumbers = DivideAbyB(AddedNumbers, 2.0);
  44.     return AddedNumbers;
  45. }
  46.